﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x02000051 RID: 81
	public class SolverManager : MonoBehaviour
	{
		// Token: 0x060003A8 RID: 936 RVA: 0x00004727 File Offset: 0x00002927
		public void Disable()
		{
			Debug.Log("IK.Disable() is deprecated. Use enabled = false instead", base.transform);
			base.enabled = false;
		}

		// Token: 0x060003A9 RID: 937 RVA: 0x000028E7 File Offset: 0x00000AE7
		public virtual void InitiateSolver()
		{
		}

		// Token: 0x060003AA RID: 938 RVA: 0x000028E7 File Offset: 0x00000AE7
		public virtual void UpdateSolver()
		{
		}

		// Token: 0x060003AB RID: 939 RVA: 0x000028E7 File Offset: 0x00000AE7
		public virtual void FixTransforms()
		{
		}

		// Token: 0x060003AC RID: 940 RVA: 0x00004740 File Offset: 0x00002940
		public void OnDisable()
		{
			if (!Application.isPlaying)
			{
				return;
			}
			this.Initiate();
		}

		// Token: 0x060003AD RID: 941 RVA: 0x00004753 File Offset: 0x00002953
		public void Start()
		{
			this.Initiate();
		}

		// Token: 0x17000050 RID: 80
		// (get) Token: 0x060003AE RID: 942 RVA: 0x0000475B File Offset: 0x0000295B
		public bool animatePhysics
		{
			get
			{
				if (this.animator != null)
				{
					return this.animator.updateMode == AnimatorUpdateMode.AnimatePhysics;
				}
				return this.legacy != null && this.legacy.animatePhysics;
			}
		}

		// Token: 0x060003AF RID: 943 RVA: 0x0000479B File Offset: 0x0000299B
		public void Initiate()
		{
			if (this.componentInitiated)
			{
				return;
			}
			this.FindAnimatorRecursive(base.transform, true);
			this.InitiateSolver();
			this.componentInitiated = true;
		}

		// Token: 0x060003B0 RID: 944 RVA: 0x000047C3 File Offset: 0x000029C3
		public void Update()
		{
			if (this.skipSolverUpdate)
			{
				return;
			}
			if (this.animatePhysics)
			{
				return;
			}
			if (this.fixTransforms)
			{
				this.FixTransforms();
			}
		}

		// Token: 0x060003B1 RID: 945 RVA: 0x0002C780 File Offset: 0x0002A980
		public void FindAnimatorRecursive(Transform t, bool findInChildren)
		{
			if (this.isAnimated)
			{
				return;
			}
			this.animator = t.GetComponent<Animator>();
			this.legacy = t.GetComponent<Animation>();
			if (this.isAnimated)
			{
				return;
			}
			if (this.animator == null && findInChildren)
			{
				this.animator = t.GetComponentInChildren<Animator>();
			}
			if (this.legacy == null && findInChildren)
			{
				this.legacy = t.GetComponentInChildren<Animation>();
			}
			if (!this.isAnimated && t.parent != null)
			{
				this.FindAnimatorRecursive(t.parent, false);
			}
		}

		// Token: 0x17000051 RID: 81
		// (get) Token: 0x060003B2 RID: 946 RVA: 0x000047EE File Offset: 0x000029EE
		public bool isAnimated
		{
			get
			{
				return this.animator != null || this.legacy != null;
			}
		}

		// Token: 0x060003B3 RID: 947 RVA: 0x00004810 File Offset: 0x00002A10
		public void FixedUpdate()
		{
			if (this.skipSolverUpdate)
			{
				this.skipSolverUpdate = false;
			}
			this.updateFrame = true;
			if (this.animatePhysics && this.fixTransforms)
			{
				this.FixTransforms();
			}
		}

		// Token: 0x060003B4 RID: 948 RVA: 0x0002C82C File Offset: 0x0002AA2C
		public void LateUpdate()
		{
			if (this.skipSolverUpdate)
			{
				return;
			}
			if (!this.animatePhysics)
			{
				this.updateFrame = true;
			}
			if (!this.updateFrame)
			{
				return;
			}
			this.updateFrame = false;
			if (this.timeStep == 0f)
			{
				this.UpdateSolver();
			}
			else if (Time.time >= this.lastTime + this.timeStep)
			{
				this.UpdateSolver();
				this.lastTime = Time.time;
			}
		}

		// Token: 0x060003B5 RID: 949 RVA: 0x0002C8B0 File Offset: 0x0002AAB0
		public void UpdateSolverExternal()
		{
			if (!base.enabled)
			{
				return;
			}
			this.skipSolverUpdate = true;
			if (this.timeStep == 0f)
			{
				this.UpdateSolver();
			}
			else if (Time.time >= this.lastTime + this.timeStep)
			{
				this.UpdateSolver();
				this.lastTime = Time.time;
			}
		}

		// Token: 0x0400025E RID: 606
		[Tooltip("If zero, will update the solver in every LateUpdate(). Use this for chains that are animated. If > 0, will be used as updating frequency so that the solver will reach its target in the same time on all machines.")]
		public float timeStep;

		// Token: 0x0400025F RID: 607
		[Tooltip("If true, will fix all the Transforms used by the solver to their initial state in each Update. This prevents potential problems with unanimated bones and animator culling with a small cost of performance. Not recommended for CCD and FABRIK solvers.")]
		public bool fixTransforms = true;

		// Token: 0x04000260 RID: 608
		public float lastTime;

		// Token: 0x04000261 RID: 609
		public Animator animator;

		// Token: 0x04000262 RID: 610
		public Animation legacy;

		// Token: 0x04000263 RID: 611
		public bool updateFrame;

		// Token: 0x04000264 RID: 612
		public bool componentInitiated;

		// Token: 0x04000265 RID: 613
		public bool skipSolverUpdate;
	}
}
